import os

def get_fuck_info(log_filename, key_name):
    tail = os.popen(f'tail -n 5 {log_filename}')
    tail_list = tail.read().splitlines()
    for res in tail_list:
        key, val = res.split(':')
        if key == key_name:
            return eval(val)

def get_t_max(log_filename):
    tail = os.popen(f'head -n 5 {log_filename}')
    tail_list = tail.read().splitlines()
    for res in tail_list:
        key, val = res.split(':')
        if key == 't_max':
            return eval(val)

def get_final_resutl(log_filename):
    tail = os.popen(f'tail -n 5 {log_filename}')
    tail_list = tail.read().splitlines()
    for res in tail_list:
        key, val = res.split(':')
        if key == 'Final result':
            return eval(val)


if __name__ == '__main__':
    res = get_fuck_info('fuck.log', 'computing_cost')
    print(res)
    print(type(res))
    res = get_fuck_info('fuck.log', 'Deadline')
    print(res[0])
    print(type(res))

    res = get_t_max('fuck.log')
    print(res)

    res = get_final_resutl('fuck.log')
    print(res)
